
     $("img").lazyload()
    is_user()
    function cart_response() {
        let user_id = getCookie("user_id")
        let token = getCookie("token")
        let options = {
            url: "http://127.0.0.1:8888/cart/list",
            type: "GET",
            dataType: "json",
            data: {
                id: user_id,
            },
            headers: {
                authorization: token,
            }
        }
        $.ajax(options)
            .done(function (res) {
                 render_cart(res)
               
            })
        
    }
    function render_cart(res) {
    $(".main_wraper").html(res.cart.map(item => 
     ` <div class="cart-container">
                <div class="goods">
                    <div class="p-goods">
                        <div class="p-img">
                            <img src="${item.img_small_logo}" alt="">
                        </div>
                        <div class="p-item">
                            ${item.title}
                        </div>
                    </div>
                    <div class="p-price">${item.current_price}</div>
                    <div class="p-quantity">
                        <div class="cartnum">
                            <button id="prev">-</button>
                            <input  id="val_num" type="text" value="${item.cart_number}" >
                            <button id="next">+</button>
                        </div>
                    </div>
                    <div class="p-sum">${item.cart_number}</div>
                    <div class="p-options">
                        <button data-id="${item.goods_id}">删除</button>
                    </div>
                </div>
            </div>`
     ).join(""))
     $("img").lazyload()
    }
    $(".main_wraper").on("click","[data-id]",remove_goods)
    //删除业务
    function remove_goods(){
        let user_id = getCookie("user_id")
        let token = getCookie("token")
        let goods_id = $(this).attr("data-id")
        // console.log($(this).attr("data-id"));
        let options ={
            url:"http://127.0.0.1:8888/cart/remove",
            type:"GET",
            dataType:"json",
            data:{
                id:user_id,
                goodsId:goods_id
            },
            headers:{
                authorization:token
            }
        }
        $.ajax(options)
        .done(function(res){
            console.log(res);
            cart_response()
        })
    }
    cart_response()

